Single cell analysis

We are ready to analyze those cells! We will use StarDist so segment cells and then measure all kinds of features.

Let's first import all needed modules again.

We should use our own model that works really well on our data set.

This is all! Now we have the cells nicely segmented with a state-of-the-art method!

We are ready to measure each and every cell. But before we do that, consider the cells at the image border. They may be clipped of and give us a wrong impression about shape but also about their intensity values. We will measure a lot of cells in the end, so we can sacrifice a few and increase our reliability by just ignoring those cells. Luckily, 'scikit-image' has just the function for that.

Now we are ready to measure. The function regionprops is made for that.

What's in the box? have a look at the result of calling regionprops.

So this is a list of regionprops objects. Have a look what regionprops returns. To output specic parameters we have to iterate through the list and call the cell feature with a specific method.

Note a few things:

We can also use the properties of 'regionprops' for plotting.

So far we just used the label image. What if we want to analyze intensity values? We can convenently give regionprops an intensity image in addition to the label image.

Since scikit-image 0.18, we can pass multiple channels to regionprops. Here we use numpy.stack to combine both images. Note: For this approach to work, make sure that the shape of the array is correct! Regionprops expects that the channel is the last dimension.

Now we can get mean intensity values of both the normalized and raw images after running regionprops.

This is nice but ideally we want to analyze the data and not just print it on the screen. A python library used frequently for data analysis is pandas. Pandas gives us functionality we know from 'R' data frames.

Pandas can convert lists to data frames if each row is again represented as a list (a so called 'list of lists'). Let's make one using list comprehension. Note that here we use the index of the channel of which we want to know the intensity parameters. If we just passed a single channel to regionprops, we would not need any index at all.

Pandas comes with some basic plotting functions that are based on 'matplotlib'. So we can explore our data with just one command. Because it is based on 'matplotlib', we can pass arguments like the figure size.

Of course we can also use boolean indexing with Pandas.

And we can easily save a pandas data frame to a csv file.